import routers from "@/router/routers"; // 这是 获取路由里面的路由数组（公共组件）
import config from "@/config";
import { getMenuByRouter, handleMenuByRouter } from "@/utils/util";

const getters = {
  token: (state) => state.user.token,
  UserInfo: (state) => state.user.originUserInfo,
  showAdmin: (state) => state.user.originUserInfo?.userRole === "admin",
  isCollapse: (state) => state.user.isCollapse,
  themeConfig: (state) => state.user.themeConfig,
  tabsMenuList: (state) => state.tabs.tabsMenuList,
  isLoginLoading: (state) => state.user.isLoginLoading,
  menuAllList: (state) => state.user.menuAllList, //没处理过的数据(一般是后端返回才会用到)
  leftMenuList: (state) => {
    if (config.menuControl === "back-end") {
      return handleMenuByRouter(state.user.menuAllList); // 后端控制路由
    } else {
      return getMenuByRouter(routers); // 前端控制路由
    }
  },
};

export default getters;
